package com.sdc.cpp;

import CppClassPrinter.CppClassPrinterPackage;
import com.sdc.abstractLangauge.AbstractClass;
import pretty.PrettyPackage;

import java.util.ArrayList;
import java.util.List;

public class CppClass extends AbstractClass {
    private final String myModifier;
    private final String myType;
    private final String myName;
    private final List<String> mySuperClasses;
    //private final String mySuperClass;
    private List<CppClassField> myFields = new ArrayList<CppClassField>();
    private List<CppClassMethod> myMethods = new ArrayList<CppClassMethod>();

    private List<CppClassMethod> myPrivateMethods = new ArrayList<CppClassMethod>();
    private List<CppClassMethod> myPublicMethods = new ArrayList<CppClassMethod>();
    private List<CppClassMethod> myProtectedMethods = new ArrayList<CppClassMethod>();

    private List<CppClassField> myPrivateFields = new ArrayList<CppClassField>();
    private List<CppClassField> myPublicFields = new ArrayList<CppClassField>();
    private List<CppClassField> myProtectedFields = new ArrayList<CppClassField>();

    private final int myTextWidth;
    private final int myNestSize;

    public String getModifier() {
        return myModifier;
    }

    public String getType() {
        return myType;
    }

    public String getName() {
        return myName;
    }

    public List<String> getSuperClasses() {
        return mySuperClasses;
    }

/*    public String getSuperClass() {
        return mySuperClass;
    }*/

    public List<CppClassField> getFields() {
        return myFields;
    }

    public List<CppClassMethod> getMethods() {
        return myMethods;
    }

    public List<CppClassMethod> getPrivateMethods() {
        return myPrivateMethods;
    }

    public List<CppClassMethod> getPublicMethods() {
        return myPublicMethods;
    }

    public List<CppClassMethod> getProtectedMethods() {
        return myProtectedMethods;
    }

    public List<CppClassField> getPrivateFields() {
        return myPrivateFields;
    }

    public List<CppClassField> getPublicFields() {
        return myPublicFields;
    }

    public List<CppClassField> getProtectedFields() {
        return myProtectedFields;
    }

    public int getNestSize() {
        return myNestSize;
    }

    public CppClass(final String modifier, final String type, final String name,
                    final List<String> implementedInterfaces, final String superClass,
                    final int textWidth, final int nestSize) {
        this.myModifier = modifier;
        this.myType = type;
        this.myName = name;
        this.mySuperClasses = implementedInterfaces;
        this.mySuperClasses.add(superClass);
        this.myTextWidth = textWidth;
        this.myNestSize = nestSize;
    }

    public void appendField(CppClassField field) {
        myFields.add(field);
        String modifier = field.getModifier();
        if (modifier.contains("public")) {
            myPublicFields.add(field);
        } else if (modifier.contains("private")) {
            myPrivateFields.add(field);
        } else if (modifier.contains("protected")) {
            myProtectedFields.add(field);
        }
    }

    public void appendMethod(CppClassMethod method) {
        myMethods.add(method);
        String modifier = method.getModifier();
        if (modifier.contains("public")) {
            myPublicMethods.add(method);
        } else if (modifier.contains("private")) {
            myPrivateMethods.add(method);
        } else if (modifier.contains("protected")) {
            myProtectedMethods.add(method);
        }

    }

    @Override
    public String toString() {
        return PrettyPackage.pretty(myTextWidth, CppClassPrinterPackage.printCppClass(this));
    }
}
